package com.city.service.pub.impl;

import com.city.domain.pub.PubFilepath;
import com.city.repository.pub.PubFilepathRepository;
import com.city.service.pub.PubFilepathService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @deprecation: 公共文件索引
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-18 13:14
 */
@Service
public class PubFilepathServiceImpl implements PubFilepathService {

    @Autowired
    private PubFilepathRepository filepathRepository;

    @Override
    public List<PubFilepath> getFileIdIndex(String tableName, String idIndex) {
        return filepathRepository.getFileIdIndex(tableName, idIndex);
    }

    @Override
    public List<PubFilepath> findAll(PubFilepath pubFilepath) {
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withMatcher("filePath", ExampleMatcher.GenericPropertyMatchers.startsWith()); //姓名采用“开始匹配”的方式查询

        //创建实例
        Example<PubFilepath> ex = Example.of(pubFilepath, matcher);

        //查询
        return filepathRepository.findAll(ex);
    }

    @Override
    public PubFilepath findByIdIndex(String time) {
        return filepathRepository.findByIdIndex(time);
    }

    @Override
    public List<PubFilepath> findListByTaskId(String taskId) {
        return filepathRepository.findListByTaskId(taskId);
    }

    @Override
    public List<PubFilepath> findByTaskIdAndRenwu(String taskId) {
        return filepathRepository.findByTaskIdAndRenwu(taskId);
    }

    @Override
    public void deleteByTaskId(String taskId) {
        filepathRepository.deleteByTaskId(taskId);
    }
}
